﻿using System.Collections.Generic;
using System.Linq;
using System.Reflection;

using Shifter.Utils;

namespace Shifter.Selectors
{
    public class FieldSelector : MultipleSelector<FieldInfo>
    {
        public override IEnumerable<FieldInfo> Select(IShifterContext context)
        {
            Assume.ArgumentNotNull(context, "context");

            var fieldList = new List<FieldInfo>
            (
                context.TypeToResolve
                    .GetTypeInfo()
                    .DeclaredFields
                    .Where(f => f.IsFamily || f.IsPublic || f.IsPrivate == context.Container.Options.ResolvePrivateMembers)
            );

            return fieldList.Where(field => field.IsDefined(typeof(InjectAttribute), false));
        }
    }
}